package org.dromara.tearoom.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttAsyncClient;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * 公共的回调地址
 * @author CKJ
 * @description: 公共的回调地址
 * @date 2025/4/15 17:58
 */
@Slf4j
public class PublicCallback implements MqttCallback {
    /**
     * 与服务器断开的回调
     */
    @Override
    public void connectionLost(Throwable throwable) {
//        throwable.printStackTrace();
        log.error("MQTT连接有异常{}：" ,throwable.getMessage());
    }

    /**
     * 订阅的回调
     * 消息到达的回调
     */
    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) {
        // 这里不再处理消息，交给各个主题的 IMqttMessageListener 处理
    }


    /**
     * 发布的回调
     * 消息发布成功的回调
     */
    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {
        IMqttAsyncClient client = token.getClient();
        log.info("{},发布消息成功！",client.getClientId() );
    }

}
